<%@ page import="java.util.ArrayList" %>
<%@ page import="com.situ.web.entity.Student" %>
<%@ page import="com.situ.web.util.PageInfo" %>
<%@ page import="com.situ.web.entity.Teacher" %><%--
  Created by IntelliJ IDEA.
  User: 24186
  Date: 2022-01-28
  Time: 18:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="/JavaWeb/static/bootstrap-3.4.1-dist/css/bootstrap.css"/>
</head>
<body>
    <a class="btn btn-primary" href="<%=request.getContextPath()%>/student_insert.jsp">insert</a>
    <table class="table table-striped table-bordered table-hover table-condensed">
        <tr>
            <td>ID</td>
            <td>Name</td>
            <td>Age</td>
            <td>Address</td>
            <td>Delete/Edit</td>
        </tr>
<%--        <%%>中可以嵌套java代码--%>
        <%
            PageInfo pageInfo =
                    (PageInfo) request.getAttribute("pageInfo");
            ArrayList<Teacher> list = (ArrayList<Teacher>) pageInfo.getList();
            for (Teacher teacher : list) {
        %>
                <tr>
                    <td><%=teacher.getId()%></td>
                    <td><%=teacher.getName()%></td>
                    <td><%=teacher.getAge()%></td>
                    <td><%=teacher.getAddress()%></td>
<%--                    <td><a href="<%=request.getContextPath()%>/student?method=deleteById&id=<%=student.getId()%>"/>delete</td>--%>
                    <td>
                        <a class="btn btn-danger btn-sm" href="javascript:void(0)" onclick="deleteById(<%=teacher.getId()%>)">delete</a>
                        <a class="btn btn-warning btn-sm" href="<%=request.getContextPath()%>/student?method=selectById&id=<%=teacher.getId()%>">edit</a>
                    </td>
                </tr>
        <%
            }
        %>
    </table>

    <nav aria-label="Page navigation">
        <ul class="pagination">
                <%
                    if(pageInfo.getPageNo()>1){
                %>
                        <li>
                        <a href="<%=request.getContextPath()%>/teacher?method=selectByPage&pageNo=<%=pageInfo.getPageNo()-1%>" aria-label="Previous">
                            <span aria-hidden="true">&laquo;</span>
                        </a>
                        </li>
                <%
                    }
                else {
                %>
                    <li>
                        <a class="disabled" href="" aria-label="Previous">
                            <span aria-hidden="true">&laquo;</span>
                        </a>
                    </li>
                <%
                }
                %>

            <%
                for (int i = 1; i <= pageInfo.getTotalPage() ; i++) {
            %>
                    <li><a href="<%=request.getContextPath()%>/teacher?method=selectByPage&pageNo=<%=i%>"><%=i%></a></li>
            <%
                }
            %>
                <%
                    if(pageInfo.getPageNo()<pageInfo.getTotalPage()){
                %>
            <li>
                <a href="<%=request.getContextPath()%>/teacher?method=selectByPage&pageNo=<%=pageInfo.getPageNo()+1%>" aria-label="Next">
                    <span aria-hidden="true">&raquo;</span>
                </a>
            </li>
                <%
                }
                else {
                %>
            <li>
                <a class="disabled" href="" aria-label="Next">
                    <span aria-hidden="true">&raquo;</span>
                </a>
            </li>
                <%
                    }
                %>

<%--            <li>--%>
<%--                <a href="#" aria-label="Next">--%>
<%--                    <span aria-hidden="true">&raquo;</span>--%>
<%--                </a>--%>
<%--            </li>--%>
        </ul>
    </nav>

    <script type="text/javascript">
        function deleteById(id) {
            var isDelete = confirm("你确认要删除吗?");
            if(isDelete){
                location.href = "<%=request.getContextPath()%>/student?method=deleteById&id="+id;
            }
        }
    </script>

<%--    ${list}--%>
</body>
</html>
